package com.darsystems.foghourz.client;

import com.googlecode.gchart.client.GChart;

public class GChartEx extends GChart {
	private static final double millsecondsPerDay = 24*3600*1000;
	
	GChartEx() {
	     setChartSize(200, 300);

	     getYAxis().setTickLabelFormat("=(Date)MM/dd");
	     
	     
	     getXAxis().setTickLabelFormat("000%");
	     getXAxis().setTickCount(5);
	     
	     addCurve();
	     getCurve().getSymbol().setSymbolType(SymbolType.LINE);

	  }

	public void fill(DailyWork[] workedHours) {
		getCurve().clearPoints();
		
		long d0 = workedHours[0].getWorkDate().getTime();
		long dn = workedHours[workedHours.length - 1].getWorkDate().getTime();
		
		int dayspan = (int)(((dn - d0)/millsecondsPerDay) + 0.5);
		int ticksPerLabel = dayspan / 15 + 1;
		getYAxis().setTickCount(dayspan + 1);
		getYAxis().setTicksPerLabel(ticksPerLabel);
		
		for (DailyWork dw : workedHours)
	     {
	    	 getCurve().addPoint(dw.getHoursWorked()/9.0, dw.getWorkDate().getTime());
	     }
	}
}
